package com.learning.spring.cloud.ms.consumer.movie.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName: RibbonConfig
 * Description: Ribbon 配置
 * <p>
 * 1- 自定义的配置类，如果被主程序上下文的 @ComponentScan 扫描到，那么该类的配置信息将被所有的@RibbonClient共享
 * 2- 如果真想给某个@RibbonClient使用，可以手动指定不扫描或者修改类的包路径。
 * <p>
 * Date: 2019/6/4 11:22 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Configuration
public class RibbonConfig {


    /**
     * 自动配置类：RibbonAutoConfiguration
     * Ribbon 客户端配置：RibbonClientConfiguration，主要一下组件
     *
     * BeanType             - beanName                  - ClassName
     * IClientConfig        - ribbonClientConfig        - DefaultClientConfigImpl
     * IRule                - ribbonRule                - ZoneAvoidanceRule
     * IPing                - ribbonPing                - DummyPing
     * ServerList           - ribbonServerList          - ConfigurationBasedServerList
     * ServerListUpdater    - ribbonServerListUpdater   - PollingServerListUpdater
     * ILoadBalancer        - ribbonLoadBalancer        - ZoneAwareLoadBalancer
     * ServerListFilter     - ribbonServerListFilter    - ZonePreferenceServerListFilter
     * RetryHandler         - retryHandler              - DefaultLoadBalancerRetryHandler
     * RibbonLoadBalancerContext - ribbonLoadBalancerContext - RibbonLoadBalancerContext
     * ServerIntrospector   - serverIntrospector        - DefaultServerIntrospector
     *
     */


    /**
     * 如修改负载规则:
     *
     * @return
     */
    @Bean
    public IRule ribbonRule() {
        // 负载均衡规则，改为随机
        return new RandomRule();
    }
}
